package com.xxl.job.executor.sjbank.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.executor.sjbank.mapper.CreditAccountMapper;
import com.xxl.job.executor.sjbank.pojo.CreditAccountEventDtl;
import com.xxl.job.executor.sjbank.service.CreditAccountEventDtlService;
import com.xxl.job.executor.sjbank.mapper.CreditAccountEventDtlMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;

import static com.xxl.job.executor.plugin.JPubUtils.*;

/**
 * @author tsu
 * @description 针对表【credit_account_event_dtl(信用卡已出/未出账单流水表)】的数据库操作Service实现
 * @createDate 2024-05-08 23:44:19
 */
@Service
public class CreditAccountEventDtlServiceImpl extends ServiceImpl<CreditAccountEventDtlMapper, CreditAccountEventDtl>
        implements CreditAccountEventDtlService {

    @Resource
    CreditAccountMapper creditAccountMapper;
    @Resource
    CreditAccountEventDtlMapper creditAccountEventDtlMapper;

    @Override
    public void syncEventDtl() {
        XxlJobHelper.log("XXL-JOB, syncEventDtl:同步账单流水表T+1开始.");
        List<LinkedHashMap> ieList = creditAccountMapper.selectEvent();
        List<LinkedHashMap> meList = creditAccountMapper.selectEventUpl();

        XxlJobHelper.log("XXL-JOB,【信用卡流水】:{}条 >>>>【UPL账单流水】:{}条", ieList.size(), meList.size());
        ieList.forEach(x -> {
            try {
                CreditAccountEventDtl creditAccountEventDtl = new CreditAccountEventDtl();
                creditAccountEventDtl.setAcctnbr(ObjectToString(x.get("acctnbr")));
                creditAccountEventDtl.setInpDate(ObjectToInt(x.get("inp_date")));
                creditAccountEventDtl.setInpTime(ObjectToInt(x.get("inp_time")));
                creditAccountEventDtl.setTransType(ObjectToString(x.get("trans_type")));
                creditAccountEventDtl.setAcptorId(ObjectToString(x.get("acptor_id")));
                creditAccountEventDtl.setAuthCode(ObjectToString(x.get("auth_code")));
                creditAccountEventDtl.setBillAmt(ObjectToBigDecimal(x.get("bill_amt")));
                creditAccountEventDtl.setBillAmtflag(ObjectToString(x.get("bill_amtflag")));
                creditAccountEventDtl.setCardNbr(ObjectToString(x.get("card_nbr")));
                creditAccountEventDtl.setCurrncyCd(ObjectToInt(x.get("currncy_cd")));
                creditAccountEventDtl.setDesLine1(ObjectToString(x.get("des_line1")));
                creditAccountEventDtl.setDesLine2(ObjectToString(x.get("des_line2")));
                creditAccountEventDtl.setOrgnAmt(ObjectToLong(x.get("orgn_amt")));
                creditAccountEventDtl.setOrgnAmtflag(ObjectToString(x.get("orgn_amtflag")));
                creditAccountEventDtl.setOrgnCurr(ObjectToInt(x.get("orgn_curr")));
                creditAccountEventDtl.setXtranno(ObjectToLong(x.get("xtranno")));
                creditAccountEventDtl.setMonthNbr(ObjectToInt(x.get("month_nbr")));
                creditAccountEventDtl.setMerchant(ObjectToString(x.get("merchant")));
                creditAccountEventDtl.setBatchDay(ObjectToInt(x.get("batch_day")));
                creditAccountEventDtlMapper.insert(creditAccountEventDtl);
            } catch (Exception e) {
                XxlJobHelper.log("XXL-JOB, 信用卡账单流水:错误日志:" + e + ">>>>>【异常列】：" + x);
            }
        });
        meList.forEach(x -> {
            try {
                CreditAccountEventDtl creditAccountEventDtl = new CreditAccountEventDtl();
                creditAccountEventDtl.setAcctnbr(ObjectToString(x.get("lending_ref")));
                creditAccountEventDtl.setBatchDay(ObjectToInt(x.get("core_ref_dt")));
                creditAccountEventDtl.setInpTime(ObjectToInt(x.get("core_ref_time")));
                creditAccountEventDtl.setXtranno(ObjectToLong(x.get("core_ref_no")));
                creditAccountEventDtl.setTransType(ObjectToString(x.get("trans_type")));
                creditAccountEventDtl.setBillAmt(ObjectToBigDecimal(x.get("amount")));
                creditAccountEventDtl.setBillAmtflag(ObjectToString(x.get("dr_cr_ind")));
                creditAccountEventDtl.setCurrncyCd(ObjectToInt(x.get("ccy_cd")));
                creditAccountEventDtl.setDesLine1(ObjectToString(x.get("aabstract")));
                creditAccountEventDtlMapper.insert(creditAccountEventDtl);
            } catch (Exception e) {
                XxlJobHelper.log("XXL-JOB, UPL账单流水:错误日志:" + e + ">>>>>【异常列】：" + x);
            }
        });
        XxlJobHelper.log("XXL-JOB, syncEventDtl:同步账单流水表T+1结束.");
    }
}




